package com.wuliu.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.wuliu.common.annotation.Log;
import com.wuliu.common.core.controller.BaseController;
import com.wuliu.common.core.domain.AjaxResult;
import com.wuliu.common.enums.BusinessType;
import com.wuliu.common.core.domain.entity.SysAccountConfig;
import com.wuliu.system.service.ISysAccountConfigService;
import com.wuliu.common.utils.poi.ExcelUtil;
import com.wuliu.common.core.page.TableDataInfo;

/**
 * 配置字典Controller
 * 
 * @author realue
 * @date 2023-10-28
 */
@Api(tags = {"账套参数控制器"})
@RestController
@RequestMapping("/system/sysConfig")
public class SysAccountConfigController extends BaseController {
    @Resource
    private ISysAccountConfigService sysAccountConfigService;

    /**
     * 查询配置字典列表
     */
    @ApiOperation(value = "查询")
    @PreAuthorize("@ss.hasPermi('system:sysConfig:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysAccountConfig sysAccountConfig) {
        sysAccountConfig.setSysAccount(getSysAccount());
        startPage();
        List<SysAccountConfig> list = sysAccountConfigService.selectSysAccountConfigList(sysAccountConfig);
        return getDataTable(list);
    }

    /**
     * 导出配置字典列表
     */
    @ApiOperation(value = "导出")
    @PreAuthorize("@ss.hasPermi('system:sysConfig:export')")
    @Log(title = "配置字典", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysAccountConfig sysAccountConfig) {
        sysAccountConfig.setSysAccount(getSysAccount());
        List<SysAccountConfig> list = sysAccountConfigService.selectSysAccountConfigList(sysAccountConfig);
        ExcelUtil<SysAccountConfig> util = new ExcelUtil<SysAccountConfig>(SysAccountConfig.class);
        util.exportExcel(response, list, "配置字典数据");
    }

    /**
     * 获取配置字典详细信息
     */
    @ApiOperation(value = "详细")
    @PreAuthorize("@ss.hasPermi('system:sysConfig:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(sysAccountConfigService.selectSysAccountConfigById(id));
    }

    /**
     * 新增配置字典
     */
    @ApiOperation(value = "新增")
    @PreAuthorize("@ss.hasPermi('system:sysConfig:add')")
    @Log(title = "配置字典", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysAccountConfig sysAccountConfig) {
        sysAccountConfig.setSysAccount(getSysAccount());
        sysAccountConfig.setCreateBy(getUsername());
        return toAjax(sysAccountConfigService.insertSysAccountConfig(sysAccountConfig));
    }

    /**
     * 修改配置字典
     */
    @ApiOperation(value = "编辑")
    @PreAuthorize("@ss.hasPermi('system:sysConfig:edit')")
    @Log(title = "配置字典", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysAccountConfig sysAccountConfig) {
        sysAccountConfig.setUpdateBy(getUsername());
        return toAjax(sysAccountConfigService.updateSysAccountConfig(sysAccountConfig));
    }

    /**
     * 删除配置字典
     */
    @ApiOperation(value = "删除")
    @PreAuthorize("@ss.hasPermi('system:sysConfig:remove')")
    @Log(title = "配置字典", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(sysAccountConfigService.deleteSysAccountConfigByIds(ids));
    }
}
